<template>
	<z-nav-bar title="提问解答"></z-nav-bar>
	<view class="z-font-32 text-w">球员</view>
	<view class="flex_fsc uni-mt-32">
		<image :src="setting.oss_pub_domain + playInfo.avatar" class="user-head"></image>
		<view style="color: #585c66">{{ playInfo.name }}</view>
	</view>
	<view class="flex_sbc uni-mt-60">
		<view class="z-font-32 text-w">解决方案</view>
		<view class="supplement" @click="associatedSolution">补充</view>
	</view>
	<scroll-view v-if="askDetails.schemeList && askDetails.schemeList.length" scroll-x class="width-100">
		<view class="flex_fsc">
			<view
				v-for="(scheme, index) in askDetails.schemeList"
				class="text-c uni-mr-20 uni-mt-28 flex_sh"
				style="position: relative"
			>
				<image :src="setting.oss_pub_domain + scheme.coverImage" class="screening-img" mode="aspectFill"></image>
				<view class="uni-mt-12 u-line-1" style="color: #585c66;width: 184rpx;">{{ scheme.name }}</view>
				<image
					:src="setting.oss_pub_domain + '/app-img/icon/icon-delete.png'"
					class="delete-icon"
					@click="askDetails.schemeList.splice(index, 1)"
				></image>
			</view>
		</view>
	</scroll-view>
	<view v-else class="add flex_cc uni-mt-44" @click="associatedSolution">
		<uni-icons type="plusempty" size="30" color="#008965"></uni-icons>
		<view>选择方案</view>
	</view>
	<!-- <view class="z-font-32 uni-mt-44">选择近期常用的方案</view>
	<scroll-view scroll-x class="width-100 uni-mt-24">
		<view class="flex_fsc">
			<view class="text-c uni-mr-20">
				<image :src="setting.oss_pub_domain + '/app-img/my/pc.png'" class="screening-img"></image>
				<view class="uni-mt-12" style="color: #585c66">击球训练方案</view>
			</view>
		</view>
	</scroll-view>
	<view class="z-font-32 uni-mt-44">解决方案智能选择</view>
	<scroll-view scroll-x class="width-100 uni-mt-24">
		<view class="flex_fsc">
			<view class="text-c uni-mr-20">
				<image :src="setting.oss_pub_domain + '/app-img/my/pc.png'" class="screening-img"></image>
				<view class="uni-mt-12" style="color: #585c66">击球训练方案</view>
			</view>
		</view>
	</scroll-view> -->
	<view class="z-font-32 text-w uni-mt-60">回复球员</view>
	<textarea
		v-model="askDetails.result.desc"
		placeholder="说点什么吧..."
		class="text-area"
		placeholder-class="uni-placeholder"
	></textarea>
	<view class="z-font-32 text-w uni-mt-60">添加视频或图片</view>
	<z-preview-media :srcStr="askDetails.result.material" :addButton="true" :delIcon="true" @change="addMedia"></z-preview-media>
	<bottom-box :buts="buts" @change="butChange"></bottom-box>
</template>

<script setup>
import { questionAnswering } from '@/api/player.js';
import { onShow } from '@dcloudio/uni-app';
import { ref, reactive, getCurrentInstance } from 'vue';
const { proxy: that } = getCurrentInstance();
const eventChannel = that.getOpenerEventChannel()
const playInfo = uni.getStorageSync('player-info')
console.log(playInfo);
const askDetails = reactive(uni.getStorageSync('ask-details'));
console.log(askDetails);

const buts = [
	{
		label: '确认提交',
		bgColor: 'uni-color-main-bg'
	}
];
function butChange(e) {
	if (!askDetails.result.schemeIdList.length) return that.tools.alert('请添加解决方案');
	questionAnswering({
			result: JSON.stringify(askDetails.result),
			status: 1
		},
		askDetails.id
	).then((res) => {
		that.tools.alert('提问解答完成');
		askDetails.status = 1
		eventChannel.emit('resolveDone', askDetails)
		uni.navigateBack();
	});
}

function associatedSolution() {
	uni.setStorageSync('select-scheme', askDetails.schemeList || []);
	uni.navigateTo({
		url: '/pages/scheme/course-select/course-select',
		events: {
			relScheme(data) {
				askDetails.schemeList = data;
				askDetails.result.schemeIdList = data.map((item) => item.id);
			}
		}
	});
}

function addMedia(e) {
	askDetails.result.material = e;
}


</script>

<style lang="scss">
@import 'answer.scss';
</style>
